﻿using shop.Bll;
using shop.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using unvell.ReoGrid;
using shop.Bll.Logi;
//using Top.Api;
//using Top.Api.Request;
//using Top.Api.Response;

namespace shop.Logi
{
    public partial class QueryExpressForm : DockContent
    {

        shop.Bll.trade.TradeBll bll = new shop.Bll.trade.TradeBll();


        public QueryExpressForm()
        {
            InitializeComponent();
        }

        private void btn_Query_Click(object sender, EventArgs e)
        {
            ////输入文本框分析快递单号

            //var list = await bll.testQuery();

            //new GridDataBuilder(this.grid1)
            //    .UseData(list)
            //    .End();

            ////

            ////使用ahk调用猪猪快递云客户端, 批量查询
            //Process.Start(".\\AhkQueryExpress\\runZhuzhu.ahk");

        }

        private async void btn_CheckExpress_Click(object sender, EventArgs e)
        {

            var begin = new DateTime(2023, 4, 25, 10, 0, 0);
            var end = new DateTime(2023, 4, 25, 10, 55, 0);
            var list = await bll.Query(begin, end);


        }

        private async void btn_syncExpress_Click(object sender, EventArgs e)
        {
            //var api = await new WdtApi()
            //    .UseUrl("logistics_sync_query.php")
            //    .AddParam("limit", "100")
            //    .Post<logistics_sync_queryResult>();


            //MessageBox.Show(api.ToString());


            await new QueryLogisticsBll().SyncFromWdt();

        }

        private async void btn_stockout_Click(object sender, EventArgs e)
        {
            var begin = DateTime.Today.AddDays(-3);
            var end = DateTime.Today;

            var res = await new QueryLogisticsBll().stockout_order_query_trade(begin, end,0);

            
            new unvell.ReoGrid.GridDataBuilder(this.grid1)
                //.UseSheetName("aaaa")
                .UseData(res.stockout_list)
                .End();

        }

        private void guanButton1_Click(object sender, EventArgs e)
        {

            //// TOP服务地址，正式环境需要设置为http://gw.api.taobao.com/router/rest
            //string serverUrl = "http://gw.api.tbsandbox.com/router/rest";
            //string appKey = "test"; // 可替换为您的沙箱环境应用的AppKey
            //string appSecret = "test"; // 可替换为您的沙箱环境应用的AppSecret
            //string sessionKey = "test"; // 必须替换为沙箱账号授权得到的真实有效SessionKey


            //ITopClient client = new DefaultTopClient(serverUrl, appKey, appSecret);

            //TradeFullinfoGetRequest req = new TradeFullinfoGetRequest();

            //req.Fields = "tid,type,status,payment,orders,promotion_details";

            //req.Tid = 123456789L;

            //TradeFullinfoGetResponse rsp = client.Execute(req, sessionKey);

            //Console.WriteLine(rsp.Body);
        }

        private async void btn_QueryExpressCompany_Click(object sender, EventArgs e)
        {
            var res = await new QueryLogisticsBll().QuerylogisticsCompany();


            new unvell.ReoGrid.GridDataBuilder(this.grid1)
                //.UseSheetName("aaaa")
                .UseData(res)
                .End();
        }
    }
}
